package com.xdf.ecommerce.account;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.xml.ws.soap.Addressing;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * = e-commerce-account-service.entity.EcommerceAddress
 * @author chanchaw
 * @create 2025-10-25 16:03
 */
@ApiModel(description = "用户地址信息 = e-commerce-account-service.entity.EcommerceAddress")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AddressInfo implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "用户ID")
    private Long userId;// 用户主键
    @ApiModelProperty(value = "一个用户的多个地址")
    private List<AddressItem> addressItems;

    @ApiModel(description = "用户的单个地址信息")
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class AddressItem {
        @ApiModelProperty(value = "地址表主键")
        private Long id;
        @ApiModelProperty(value = "用户姓名")
        private String username;
        @ApiModelProperty(value = "手机号码")
        private String phone;
        @ApiModelProperty(value = "省份")
        private String province;
        @ApiModelProperty(value = "城市")
        private String city;
        @ApiModelProperty(value = "详细地址")
        private String addressDetail;
        @ApiModelProperty(value = "创建时间")
        private LocalDateTime createTime;
        @ApiModelProperty(value = "最后一次时间")
        private LocalDateTime updateTime;

        public AddressItem(Long id){
            this.id = id;
        }

        public UserAddress toUserAddress(AddressItem addressItem){
            UserAddress ret = new UserAddress();
            ret.setUsername(addressItem.getUsername());
            ret.setPhone(addressItem.getPhone());
            ret.setProvince(addressItem.getProvince());
            ret.setCity(addressItem.getCity());
            ret.setAddressDetail(addressItem.getAddressDetail());
            return ret;
        }
    }
}
